<?php

namespace app\admin\controller;

use app\admin\logic\MemberLogic;
use app\common\controller\AdminAuthController;
use app\common\validate\MemberValidate;
use think\App;

/**
 * Class Member
 * @package app\admin\controller
 */
class Member extends AdminAuthController
{

    public function __construct(App $app = NULL)
    {
        parent::__construct($app);
        $this->validate = MemberValidate::instance();
        $this->logic = MemberLogic::instance();
    }

    /**
     * 数据列表
     * @return Json
     */
    public function index()
    {
        $get = input_param([
            'page' => 1,
            'keywords' => '',
            'limit' => 20,
        ]);
        $this->validate->runCheck($get, '', __FUNCTION__);
        $data['list'] = $this->logic->getList($get)
                                    ->hidden(['password'])
                                    ->toArray();
        $data['count'] = $this->logic->getCount($get);
        return $this->json_responce($data);
    }

    public function read()
    {

        $get = input_param([
            'id' => '',
        ]);
        $this->validate->runCheck($get, '', __FUNCTION__);
        $data['info'] = $this->logic->getByID($get)
                                    ->hidden(['password'])
                                    ->toArray();
        return $this->json_responce($data);
    }

    public function save()
    {

        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->createData($param);
        return $this->json_responce();
    }

    public function update()
    {

        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->updateByID($param);
        return $this->json_responce();
    }

    public function delete()
    {

        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->delByID($param);
        return $this->json_responce();
    }

    public function deletes()
    {

        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->delByIDs($param);
        return $this->json_responce();
    }

    public function enables()
    {

        $param = $this->param;
        $this->validate->runCheck($param, '', __FUNCTION__);
        $data = $this->logic->enableByIDs($param);
        return $this->json_responce();
    }

}
